<!--
 * @Descripttion: 快递配置
 * @Author: xiao li
 * @Date: 2021-04-12 18:06:07
 * @LastEditors: xiao li
 * @LastEditTime: 2021-11-19 18:39:06
-->
<template>
  <div class="lb-sys-sproconfig">
    <top-nav></top-nav>
    <div class="page-main">
      <lb-tips>
        <p>
          快递鸟：免费版主流快递仅支持（圆通、申通、百世、天天）的查询，每家每天可查询100次
        </p>
      </lb-tips>
      <el-form
        @submit.native.prevent
        :model="subForm"
        :rules="subFormRules"
        ref="subForm"
        label-width="140px"
        class="config-form"
      >
        <el-form-item required label="请选择快递方式">
          <el-select v-model="subForm.type" placeholder="请选择">
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <block v-if="subForm.type === 1">
          <el-form-item label="bird_id" prop="bird_id">
            <el-input
              v-model="subForm.bird_id"
              placeholder="请输入bird_id"
            ></el-input>
            <lb-tool-tips
              >请输入快递鸟bird_id，输入错误会影响小程序的正常使用，谨慎修改</lb-tool-tips
            >
          </el-form-item>
          <el-form-item label="bird_key" prop="bird_key">
            <el-input
              v-model="subForm.bird_key"
              placeholder="请输入bird_key"
            ></el-input>
            <lb-tool-tips
              >请输入快递鸟bird_key，输入错误会影响小程序的正常使用，谨慎修改</lb-tool-tips
            >
          </el-form-item>
        </block>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo">{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      typeList: [{
        value: 1,
        label: '快递鸟'
      }],
      subForm: {
        type: 1,
        bird_id: '',
        bird_key: ''
      },
      subFormRules: {
        type: { required: true, type: 'string', message: '请选择快递方式', trigger: 'blur' },
        bird_id: { required: true, type: 'string', message: '请输入bird_id', trigger: 'blur' },
        bird_key: { required: true, type: 'string', message: '请输入bird_key', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    async getFormInfo () {
      let { code, data } = await this.$api.systemExpressInfo()
      if (code !== 200) return
      for (let key in this.subForm) {
        this.subForm[key] = data[key]
      }
    },
    submitFormInfo () {
      this.$refs['subForm'].validate(valid => {
        if (valid) {
          let { subForm } = this
          console.log(subForm)
          this.$api.systemExpressUpdate(subForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-sys-sproconfig {
  width: 100%;
  .config-form {
    .el-select,
    .el-input {
      width: 300px;
    }
  }
}
</style>
